<?php 
	class Teacher extends Controller{
		function Teacher(){
			parent::Controller();
		}

		function index(){
			$data['id'] = $this->session->userdata('id');
			$gate['body'] = $this->load->view('teacher/teacher_home', $data, TRUE);
			$this->load->view('teacher', $gate);
		}
		
		function edit_profile(){
			$data = array();
			//$reguser = array();
			$data['id'] = $this->session->userdata('userid');	
			$reguser = $this->Register->selectTeacher($data['id']);

			$rules['lastname'] = "required";
			$rules['firstname'] = "required";
			$rules['middlename'] = "required";
			$rules['mobilenumber'] = "required";
			$rules['aboutme'] = "required";
			$rules['academiccredentials'] = "required";

			$this->validation->set_rules($rules);
			$this->validation->set_error_delimiters('<div id="error">', '</div>');

			if ($this->validation->run()==TRUE){
				$reguser["lastname"] = $this->input->post("lastname");
				$reguser["firstname"] = $this->input->post("firstname");
				$reguser["middlename"] = $this->input->post("middlename");
				$reguser["mobilenumber"] = $this->input->post("mobilenumber");
				$reguser["birthdate"] = $this->input->post("y") . "-" . $this->input->post("m") . "-" . $this->input->post("d");
				$reguser["sex"] = $this->input->post("sex");
				$reguser["aboutme"] = $this->input->post("aboutme");
				$reguser["academiccredentials"] = $this->input->post("academiccredentials");
				$this->Register->updateTeacher($reguser, $this->session->userdata('userid'));
			}

			$data['reguser'] = $reguser;
			$gate["body"] = $this->load->view("teacher/edit_profile", $data, TRUE);
			$this->load->view('teacher', $gate);
		}
		
		function approved_schedule(){
			$data = array();
			$schedule["body"] = $this->load->view("teacher/schedule", $data, TRUE);
			$this->load->view("teacher", $schedule);
		}
		
		function create_schedule(){
			$rules = array();
			//$rules["date"] = "required";
			$rules["time"] = "required";
			$this->validation->set_rules($rules);
			
			$fields = array();
			//$fields["date"] = "Date:";
			$fields["time"] = "Time:";
			$this->validation->set_fields($fields);
			
			$userid = $this->session->userdata("userid");
			
			if($this->validation->run() == TRUE){
				$new["date"] = $this->input->post("y") . "-" . $this->input->post("m") . "-" . $this->input->post("d");
				$new["time"] = $this->input->post("time") . ":00";
				$new["subjectid"] = $this->input->post("subject");
				$new["teacherid"] = $userid;
				
				//$this->load->model("createsched");
				$this->CreateSched->insert($new);
				$this->CreateSched->maketeach($new["teacherid"], $new["subjectid"]);
				
			}
			$data = array();
			$createsched["body"] = $this->load->view("teacher/createsched", $data, TRUE);
			$this->load->view("teacher", $createsched);
		}
	}
?>
